from random import Random

from foodmarket.settings import MEDIA_HOST


def image_to_url(image):
    try:
        return MEDIA_HOST + image.url
    except ValueError:
        return ''


RANDOM_CHARS = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'


def random_32_str():
    random_str = ''
    length = len(RANDOM_CHARS) - 1
    random = Random()
    for i in range(32):
        random_str += RANDOM_CHARS[random.randint(0, length)]
    return random_str
